home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / cli / mx2src.arc / SPOOLER.MOD < prev    next >
Text File  |  1989-01-05  |  5KB  |  137 lines

  1. (* this module uses spint 0 to communicate with a controller program
  2.    Commands are sent via the spintinfo call. and pass values thru
  3.    the spintcmd variable. Please look at lp.mod for an example.
  4.    current commands are:
  5.    1    examine spool directory. print any files that exist then delete.
  6.    2    spool queue.
  7.    99   terminate spooler.prg.
  8. *)
  9.  
  10. MODULE spooler;
  11. FROM   XBIOS    IMPORT  SuperExec;
  12. FROM   SYSTEM   IMPORT  BYTE,ADR,CODE,ADDRESS;
  13. FROM   GEMDOS   IMPORT  DirCreate,Open,Close,SetDTA,Delete,SFirst,SNext,
  14.                         SetPath,Alloc,Free,Read,GetPath,OldTerm;
  15. FROM   TextIO   IMPORT  WriteString,WriteLn,WriteAdr;
  16. FROM   BIOS     IMPORT  Device,BCosStat,BConOut; 
  17. FROM   Streams  IMPORT  OpenStream,CloseStream,StreamKinds,Stream;
  18. FROM   SYSCALL  IMPORT  EnableSpint,SwapProcess,SleepProcess,
  19.                         WakeupProcess,ProcessPid,DisableSpint;
  20. TYPE   dtatype  =       RECORD
  21.                 res     :       ARRAY [0..20] OF BYTE;
  22.                 attr    :       BYTE;
  23.                 time    :       CARDINAL;
  24.                 date    :       CARDINAL;
  25.                 size    :       LONGCARD;
  26.                 name    :       ARRAY [0..13] OF CHAR;
  27.                         END;
  28. VAR    result,i,return,d,pid                    :       INTEGER;
  29.        DTA                                      :       dtatype;
  30.        ok                                       :       BOOLEAN;
  31.        count                                    :       INTEGER;
  32.        ch                                       :       BYTE;
  33.        S                                        :       Stream;
  34.        endpos,currentpos,delay                  :       LONGCARD;
  35.        C,char                                   :       POINTER TO CHAR;
  36.        spintcmd                                 :       ARRAY [0..1] OF
  37.                                                         LONGCARD;
  38. PROCEDURE       sq;
  39. BEGIN
  40.            WriteLn;
  41.            IF currentpos#endpos THEN
  42.                 WriteString("Printing ");
  43.                 WriteString(DTA.name);
  44.                 WriteAdr(ADDRESS(endpos),7);
  45.                 WriteString(" total characters");
  46.                 WriteAdr(ADDRESS(endpos-currentpos),7);
  47.                 WriteString(" characters left to print.");
  48.            ELSE
  49.                 WriteString("Nothing.");
  50.            END;
  51.            WriteLn;
  52. END             sq;
  53.  
  54. PROCEDURE       run;
  55. BEGIN
  56.         IF (spintcmd[0]=1) OR (spintcmd[0]=99) THEN
  57.            WakeupProcess(pid);
  58.         END;
  59.         IF spintcmd[0]=2 THEN
  60.            sq;
  61.         END;
  62. END             run;
  63.  
  64. BEGIN
  65.         spintcmd[1]:=LONGCARD(sq);
  66.         pid:=ProcessPid();
  67.         ok:=SetPath("\");
  68.         ok:=DirCreate("mx2spool");
  69.         IF ok THEN
  70.            WriteString("Creating spool directory -> \MX2SPOOL");
  71.            WriteLn;
  72.         END;
  73.         ok:=SetPath("\mx2spool");
  74.         IF NOT ok THEN
  75.            DisableSpint(0);
  76.            WriteString("Unable to create or use MX2SPOOL directory");
  77.            WriteLn;
  78.            OldTerm;
  79.         END;
  80.         ok:=EnableSpint(0,run,ADR(spintcmd)); (* spint to start spooler *)
  81.         SetDTA(ADR(DTA));
  82.         LOOP
  83.            SFirst("*.*",0,result);
  84.            WHILE result=0 DO
  85.  
  86.         count:=0;
  87.         OpenStream(S,DTA.name,READ,return);
  88.         IF return<0 THEN
  89.         ELSE
  90.            currentpos:=0;
  91.            endpos:=S.endPos;
  92.            Alloc(endpos,C);
  93.            char:=C;
  94.            IF char#NIL THEN
  95.               Read(S.handle,endpos,char);
  96.               CloseStream(S,return);
  97.               WHILE (currentpos#endpos) DO
  98.                  WHILE NOT BCosStat(PRT) DO
  99.                     INC(delay);
  100.                     IF delay>1000 THEN
  101.                        delay:=0;
  102.                        SwapProcess;
  103.                     END;
  104.                  END;
  105.                  BConOut(PRT,char^);
  106.                  INC(currentpos);
  107.                  INC(char);
  108.                  INC(count);
  109.                  IF count>32 THEN
  110.                     count:=0;
  111.                     SwapProcess;
  112.                     IF spintcmd[0]=99 THEN
  113.                        DisableSpint(0);
  114.                        OldTerm;
  115.                     END;
  116.                  END;
  117.               END;
  118.               IF Free(C) THEN END;
  119.               BConOut(PRT,CHAR(0cH)); (* send formfeed *)
  120.            ELSE
  121.               CloseStream(S,return);
  122.               WriteString(DTA.name);
  123.               WriteString(" * SPOOLER OUT OF MEMORY *");
  124.               WriteLn;
  125.            END;
  126.         END;
  127.            ok:=Delete(DTA.name);
  128.            SNext(result);
  129.            END;
  130.            SleepProcess(pid);
  131.            IF spintcmd[0]=99 THEN
  132.               DisableSpint(0);
  133.               OldTerm;
  134.            END;
  135.         END;
  136. END    spooler.
  137.